<?php
include_once(dirname(__FILE__)."/../inc/common.php"); 
$method = isset($_GET["method"])?$_GET["method"]:"";

if($method=="listQry"){
	$tagName = isset($_POST["tagName"])?$_POST["tagName"]:"";
	$pageSize = 50;
	$showInvisible = isset($_GET["showInvisible"]) && ($_GET["showInvisible"]==1)?1:0;
	$curPage = isset($_GET["curPage"])?$_GET["curPage"]:1;
	$tallyTagClass = new tally_tag();
	$tagList = $tallyTagClass->findTagByAccountId($userId, $tagName, $showInvisible, ($curPage-1)*$pageSize, $pageSize);
	$total = $tallyTagClass->countTagByAccountId($userId, $tagName, $showInvisible);
	$nownum = $tagList?count($tagList):0;
	?>
	 <!--begin:数据列表-------------------------------------------------------------------------------------------------->
	    <table id="listtb" class="listtable" cellpadding="0" cellspacing="1">
	      <thead>
	      <tr>
            <th width="5%">状态</th>
	        <th width="40%">名称</th>
			<th width="40%">类型</th> 
	        <th width="15%">使用次数</th>
	               
	      </tr>
	      </thead>
	      <tbody>
		   	<?php
			foreach($tagList as $tag){
			?>
	      <tr>
             <td>
		        <?php   if(!$tag["status"]){ ?>
            	<img style="padding-left: 1px;" src="../images/common/stop.gif"/>
            	<?php   } ?>
	        </td>
	        <td><?php echo $tag["name"]?></td>
            <td></td>
	  		<td><?php echo $tag["count"]?>
             
                <div class="oper_bar">
                   <span> 
                   		<?php if($tag["status"]){ ?>
                        <a  title="停用"  href="javascript:fGoto();" onclick="Tag.showInvisible('<?php echo $tag["id"]?>','0')">停用</a>
                   		<?php }else{ ?>
                        <a  title="启用"  href="javascript:fGoto();" onclick="Tag.showInvisible('<?php echo $tag["id"]?>','1')">启用</a>
                        <?php } ?>
                   </span>
			   </div>
           
          </td>
	       </tr>
	       <?php
			}
			?>
	       </tbody>	       
	       <tfoot>
	       <tr>
	       <td colspan="10">
	       <span class=pagebar><?php echo isspage($total,$nownum,$pageSize,$curPage); ?></span>	       	       	       	       
	       </td></tr>	       
	       </tfoot>
	    </table>
           
           <a  id="Btn3"  title="显示停用的标签"  href="javascript:fGoto();" onclick="Tag.search('1');"><span>--显示停用的标签--</span></a>
           
           
	    <!--end:数据列表区-------------------------------------------------------------------------------------------------->
	<?php
}else if($method=="add"){
	?>
<div id="winwrapper" class="winwrapper">
<form id="tagAddForm" name="tagAddForm"  method="post">
    <input type="hidden" name="tagType" id="tagType" value="0"/>
	<div class="content">
			<fieldset>
				<legend>基本信息</legend>
                <table cellpadding="0" cellspacing="1" class="form_table">
						<tr>
							<td class="caption">
							<span class="em">*</span>
				       		<label for="tagName">标签名称:</label>
							</td>
							<td class="field">
							<input name="tagName" id="tagName" type="text" class="text l"  value="" notnull="true" maxlength="15">
							</td>
						</tr>
                     <!--   <tr>
							<td class="caption">
							<span class="em">*</span>
				       		<label for="tagType">类型:</label>
							</td>
							<td class="field">
								<SELECT name="tagType" class="SELECT" id="tagType">
						    		
						      			<option value="0"  >普通标签</option>
									
						      			<option value="1"  >婚假</option>
									
						      			<option value="2"  >装修</option>
									
						      			<option value="3"  >加油</option>
												
								</SELECT>
							</td>
						</tr> --> 
                </table>
            </fieldset>
	
	        <div class="buttons">
			        <input id="saveBtn" type="button" class="button"  value="确定"  onclick="Tag.save(this);">
			        <input type="button" class="button"  value="取消" onclick="CM.close(this);return false;">	            
			</div>
			
             <div class="tip_wrapper" style="display:none">
				<a class="colse_btn" onclick="Help.goClose();" href="#" align="absmiddle"><img src="../images/icons/icon_close.gif"/></a>
				<span class="title">提示:</span>
				<span class="tip_content"></span>
			</div>
	</div>
		    	
</form>
</div>
	<?php
}else if($method=="doAdd"){
	if(isset($_POST["tagName"])){
		try{
			$tallyTagClass = new tally_tag();
			$tallyTagClass->createTag(
				$userId, $_POST["tagName"]
			);
			$result = array(
				"returnCode" => 0,
				"returnMsg" => "新增成功",
			);
		}catch(Exception $e){
			$result = array(
				"returnCode" => 2,
				"returnMsg" => $e->getMessage()?$e->getMessage():"新增失败",
			);
		}
	}else{
		$result = array(
			"returnCode" => 1,
			"returnMsg" => "参数错误",
		);
	}
	$jsonHandle = new ext_jsonHandle();
	$jsonHandle->jsonOut($result);
	exit();
}else if($method=="showInvisible"){
	if(isset($_GET["oids"])){
		$status = isset($_GET["status"]) && $_GET["status"]?1:0;
		try{
			$oids = explode(",", $_GET["oids"]);
			if($oids){
				$tallyTagClass = new tally_tag();
				foreach($oids as $oid){
					$tag = $tallyTagClass->findTagById($userId, $oid);
					if($tag){
						$tag["status"] = $status;
						$tallyTagClass->updateTagInfo($userId, $oid, $tag);
					}
				}
			}
			$result = array(
				"returnCode" => 0,
				"returnMsg" => "更新成功",
			);
		}catch(Exception $e){
			$result = array(
				"returnCode" => 2,
				"returnMsg" => $e->getMessage()?$e->getMessage():"更新失败",
			);
		}
	}else{
		$result = array(
			"returnCode" => 1,
			"returnMsg" => "参数错误",
		);
	}
	$jsonHandle = new ext_jsonHandle();
	$jsonHandle->jsonOut($result);
	exit();
}else{
?>
		
	<!-- begin:导航条 -->
	<div class="titlebar">
	   <h3>标签管理<!--  --></h3>
	</div>
	<!-- end:导航条 -->
	
<div class="tab_wrapper">
  <div class="body">
	<!-- begin:工具条 -->
	<div class="toolbar">
	<p>
	<a  id="Btn3" class="button" title="新增标签"  href="javascript:fGoto();" onclick="Tag.goAdd();"><span>新增标签</span></a>
	</p>	
	</div>
	<!-- end:工具条 -->
	<!-- begin:搜索区 -->
	<form id="schForm"  method="post">
	<div class="searchbar" id ="searchbar">
		<div class="base_condition">
		<table>
			<tr>
				<td>
					<label for="tagName">名称:</label>
					<input type="text" name="tagName"  class="text" id="tagName" maxlength="20" value="" />
				</td>
				<td>
					<input id="searchBtn" class="button" type="button" value="查询" onclick="Tag.pg.params='';Tag.search();"/>
				</td>
			</tr>
		</table>
        </div>
	</div>
	</form>
	<!-- end:搜索区 -->
	<!-- begin:-------主数据区 -------------------->
	<div id="dataView" class="data list_area">
		 <div  align="center"><img align="absmiddle" src='../images/common/loading1.gif'></div>
	</div>
	<!--end: ----------主数据区----------------->
  </div>
</div>

<?php
}
?>
